package com.edu.hre.db.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;



import com.edu.hre.db.config.BaseDAO;
import com.edu.hre.db.config.DBPool;
import com.edu.hre.db.dto.HreEmpBasicsalary;
import com.edu.hre.db.dto.HreEmpEmergencyContact;
import com.edu.hre.db.dto.HreEmpDependent;
import com.edu.hre.db.dto.HreEmpSkill;
import com.edu.hre.db.dto.HreEmpWorkExperience;


public class EmpSkillDAO  extends BaseDAO {
	private static final Logger logger = Logger.getLogger(EmpSkillDAO.class);
	public List<HreEmpSkill> getSkillByEmployeeId(
			int employeeNumber) {
		List<HreEmpSkill> listSkills = new ArrayList<HreEmpSkill>();
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		try {
			conn = DBPool.getConnection();
			String strSQLQuery = "SELECT es.years_of_exp,s.name FROM hre_emp_skill es "+
			"JOIN hre_skill s ON es.skill_id = s.id "+
			"WHERE es.emp_number = "
					+ employeeNumber;
			preStmt = conn.prepareStatement(strSQLQuery);
			rs = preStmt.executeQuery();
			while (rs.next()) {
				HreEmpSkill skill = new HreEmpSkill();
				skill.setYearsOfExp(rs.getByte("years_of_exp"));
				skill.setSkillName(rs.getString("name"));
				//.....
				//.....
				listSkills.add(skill);
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e.getMessage());
		} finally {
			// đóng PreparedStatement, ResultSet và đẩy connection vào pool
			releaseConnection(conn, preStmt, rs);
		}
		return listSkills;
	}

}
